package controller;

import entity.Data;
import entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * @author 石小俊
 */
@RestController
@RequestMapping("/ajax")
public class AjaxController {

    //    @ResponseBody
    @RequestMapping(value = "/checkUsername", produces = "text/html;charset=utf-8")
    public String checkUsername(String username) {
        // produces属性相当于response.setContentType("text/html;charset=utf-8")
        if ("admin".equals(username)) {
            return "<span style='color:red;'>该用户已经被注册</h1>";
        }
        return "<span style='color:green;'>用户名可用</h1>";
    }

    @RequestMapping("/findUser")
    public User findUser() {
        User user = new User(1, "admin", "123456", "13812345678", "江苏-南京");
        user.setBirthday(new Date());
        return user;
    }

    @RequestMapping("/findAll")
    public ModelAndView findAll() {
        ModelAndView mav = new ModelAndView();

        return mav;
    }

    @RequestMapping("findById")
    public User findById(Integer id) {
        return null;
    }

    @RequestMapping("/query")
    public List<Data> query(String spell) {
        return null;
    }

}
